package com.coolw.cola.statemachine.service.impl;

import com.alibaba.cola.statemachine.StateMachine;
import com.coolw.cola.statemachine.dto.Order;
import com.coolw.cola.statemachine.service.OrderService;
import com.coolw.cola.statemachine.enums.OrderEvent;
import com.coolw.cola.statemachine.enums.OrderStatusEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 订单服务接口实现类
 *
 * @author coolw
 * @date 2024/4/10 19:24
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Resource(name = "orderStateMachine")
    private StateMachine<OrderStatusEnum, OrderEvent, Order> orderStateMachine;

    @Override
    public void close(Order order, OrderEvent event) {
        // 触发状态机
        orderStateMachine.fireEvent(order.getOrderStatus(), event, order);
    }
}
